package cn.tedu.hospital.inventory.service.imp;

import cn.tedu.hospital.inventory.mapper.InventoryMapper;
import cn.tedu.hospital.inventory.pojo.dto.DrugAdd;
import cn.tedu.hospital.inventory.pojo.dto.InventoryQuery;
import cn.tedu.hospital.inventory.pojo.entity.Drug;
import cn.tedu.hospital.inventory.pojo.vo.QueryVO;
import cn.tedu.hospital.inventory.service.InventoryService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class InventoryServiceImp implements InventoryService {
    @Autowired
    private InventoryMapper inventoryMapper;
    @Override
    public List<QueryVO> queryInventory(InventoryQuery inventoryQuery) {
        List<QueryVO> queryVO = inventoryMapper.queryInventory(inventoryQuery);
        return queryVO;
    }

    @Override
    public void saveInventory(List<DrugAdd> drugAddList) {
        long currentTimeMillis = System.currentTimeMillis();
        Drug drug = new Drug();
        Date date = new Date();
        for (DrugAdd drugAdd : drugAddList){
            String IDCode = drugAdd.getPatientId() + "" + currentTimeMillis;
            BeanUtils.copyProperties(drugAdd,drug);
            drug.setCreateTime(date);
            drug.setIDCode(IDCode);
            inventoryMapper.saveDrug(drug);
        }
    }
}
